#include "temp.h"
#include <math.h>
#include <stdio.h>
#include "drv_timer.h"
#include "delay.h"
#include "systemdata.h"
#include "dvc.h"

static double myln(double a){
   int N = 15;
   int k,nk;
   double x,xx,y;
   x = (a-1)/(a+1);
   xx = x*x;
   nk = 2*N+1;
   y = 1.0/nk;
   for(k=N;k>0;k--){
     nk = nk - 2;
     y = 1.0/nk+xx*y; 
   }
   return 2.0*x*y;
}

//参数:1、vol_mV，转换为3.3V上拉电压下的NTC电压值
//	   2、ntvBelta，NTC电阻的β值
//返回值:有符号整型温度值(摄氏温度)
int8_t get_temp_by_vol(uint16_t vol_mV,float ntvBelta){
	float res_ntc = 10.0*vol_mV/(float)(3300 - vol_mV);
	double temp = myln(res_ntc/10.0)/ntvBelta;
	temp += 1.0/298.15;
	return (1.0/temp - 273.15);
}
